package nix.spring;

import nix.spring.domain.User;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Demo1 {

	@Test
	public void fun1() {

		// 创建容器对象
		ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
		// 从容其中获得对象
		User u = (User) ac.getBean("user");
		System.out.println(u);
	}
	
	@Test
	public void fun2() {

		// 创建容器对象
		ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
		// 从容其中获得对象
		User u1 = (User) ac.getBean("user2");
		User u2 = (User) ac.getBean("user2");
		System.out.println(u1 == u2);
	}
	
	@Test
	public void fun3() {

		// 创建容器对象
		ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
		// 从容其中获得对象
		User u1 = (User) ac.getBean("user3");
		User u2 = (User) ac.getBean("user3");
		System.out.println(u1 == u2);
	}
	
	@Test
	public void fun4() {

		// 创建容器对象
		ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
		// 从容其中获得对象
		User u = (User) ac.getBean("user4");
		System.out.println(u);
		ac.close();
	}
}
